#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;
//int main()
//{
//    
//    /*while (cin >> cur)
//    {
//        str += " ";
//        str += cur;
//    }
//    string tmp(str.begin() + 1, str.end() - (cur.size() + 1));*/
//    string str = "They are students. ";
//    string cur = "aeiou";
//    string tmp = str.substr(str.find_first_of(cur) + 1);
//    str.erase(str.find_first_of(cur) );
//    str += tmp;
//    cout << str;
//}
#include<unordered_map>
#include<vector>
#include<algorithm>
using namespace std;
//
//int main()
//{
//    int n = 0;
//    scanf("%d", &n);
//    int k = 3 * n;
//    int nums;
//    vector<int> v;
//    v.reserve(k);
//    while (k--)
//    {
//        cin >> nums;
//        v.push_back(nums);
//    }
//    sort(v.begin(), v.end());
//    int pos = v.size() - 2, sum = 0;
//    while (n--)
//    {
//        sum += v[pos];
//        pos -= 2;
//    }
//    printf("%d", sum);
//}

class Solution123
{
public:
    int repeatedNTimes(vector<int>& nums)
    {
        unordered_map<int, int> cnt;
        for (int i = 0;i < nums.size() - 1;i++)
        {
            cnt[nums[i]]++;
            if (cnt[nums[i]] * 2 == nums.size())
                return nums[i];
        }
        return -1;
    }
};
class Solution556 {
public:
    vector<string> uncommonFromSentences(string s1, string s2)
    {
        vector<string> v;
        unordered_map<string, int> cnt;
        auto pos = 0,end=0;
        while (end < s1.size())
        {
            end = s1.find(" ",pos);
            string tmp = s1.substr(pos, end - pos);
            cnt[tmp]++;
            pos = end + 1;
        }
        pos = 0,end=0;
        while (end < s2.size())
        {
            end = s2.find(" ",pos);
            string tmp = s2.substr(pos, end - pos);
            cnt[tmp]++;
            pos = end + 1;
        }
        auto it = cnt.begin();
        while (it != cnt.end())
        {
            if (it->second == 1)
                v.push_back(it->first);
            it++;
        }
        return v;
    }
};
class Solution
{
public:
    int subarraySum(vector<int>& nums, int k)
    {
        unordered_map<int, int> hash;
        hash[0] = 1;
        int sum = 0, cnt = 0;
        for (auto e : nums)
        {
            sum += e;
            if (hash.count(sum - k))
                cnt += hash.count(sum - k);
            hash[sum]++;
        }
        return cnt;
    }
};

int main()
{
	vector<int> v = { 1,-1,0};
    Solution().subarraySum(v, 0);
    
   
	return 0;
}
